import 'package:chat_app_project/screens/agora/call_page.dart';
import 'package:chat_app_project/screens/home.dart';
import 'package:chat_app_project/screens/login/login.dart';
import 'package:chat_app_project/screens/wk/conversation.dart';
import 'package:chat_app_project/theme.dart';
import 'package:chat_app_project/tool/im.dart';
import 'package:chat_app_project/util/notification_helper.dart';
import 'package:chat_app_project/util/sp_util.dart';
import 'package:fast_cached_network_image/fast_cached_network_image.dart';
import 'package:flutter/material.dart';

import 'models/const.dart';
import 'screens/agora/call_waiting.dart';

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  //初始化缓存工具类
  await SpUtil.getInstance();
  //如果登录 初始化IM
  if(UserInfo.isLogin()){
    await IMUtils.initIM();
  }
  //通知初始化
  NotificationHelper notificationHelper = NotificationHelper();
  notificationHelper.initialize();
  //初始化图片加载控件
  FastCachedImageConfig.init();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: '首页',
      theme: lightThemeData(context),
      darkTheme: darkThemeData(context),
      home:  UserInfo.isLogin()?  HomeScreen(selectedIndex: 0) : const LoginPage(),
      // home:  const CallWaitingScreen(),
    );
  }

  @override
  void initState() {
    super.initState();


    //初始化监听器
    // ImService.initListener();
    //尝试登录
    // ImService.tryConnect();
  }
}
